<?php

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
/**
 * Description of Answer
 *
 * @author hoangle
 */
class Event {

    private $db;
    
    public function  __construct() {
        $this->db = Zend_Registry::get('db');
    }
    
    /**
     * @desc Update About Me
     * @param <string> $desc
     * @return <bool> true else false | NULL
     */
    public function getEventQuestion($cate_id=NULL) {
        try {
            $sql = "SELECT el.*,q.*,et.add_new_question,et.add_new_answer FROM event_log el ";
            $sql .= "INNER JOIN event_type et ON el.event_type = et.id ";
            $sql .= "INNER JOIN question q ON el.question_id = q.id ";
            $where = "WHERE (et.add_new_question = 1 OR et.add_new_answer = 1) ";
            if($cate_id<>NULL){
                $sql .= "INNER JOIN category c ON c.id = q.cate_id ";
                $sql .= "LEFT JOIN category c2 ON c2.cate_up_level = c.id ";
                $where .= "AND (c.id = ".$cate_id." OR c2.id = ".$cate_id.")";
            }
            $sql .= $where;
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->fetchAll();
            $stmt->closeCursor();
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return $result;
    }

}

?>
